#include <string>

#include "consumable.h"
#include "defines.h"
#include "manager.h"
#include "monster.h"
#include "tile.h"

using std::string;

Consumable::Consumable( int x, int y, string name, char symbol ) : Item( x, y, name, symbol )
{
	type_.consumable = 1;
	effectType = nullptr;
	effectStrength = 1;
}

Consumable::Consumable( const consumable_t baseConsumable, int x, int y )
	: Item( x, y, baseConsumable.name, baseConsumable.symbol )
{
	type_.consumable = 1;
	effectType = baseConsumable.effect;
	effectStrength = baseConsumable.strength;
	color = baseConsumable.color;
}

int Consumable::effect( Monster * m )
{
	if( effectType )
		return effectType( m, effectStrength );
	return 0;
}

int ( *Consumable::getEffect() )( Monster *, int )
{
	return effectType;
}

void Consumable::setEffect( int ( *newEffect )( Monster * m, int strength ) )
{
	effectType = newEffect;
}

int effectHeal( Monster * m, int strength )
{
	m->heal( strength );
	if( m == manager.getPlayer() )
		manager.addMsg( "Your wounds heal." );
	else
		manager.addMsg( m->name + " suddenly looks more healthy." );
	return strength;
}

int effectHarm( Monster * m, int strength )
{
	m->harm( strength );
	return 0;
}